<%@ page import="xxd.SysInitData" %>

<%
    if(!xxd.SysInitData.isAvailable){
        response.sendRedirect( "${request.getContextPath()}/error.html"  )
    }
%>

<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" src="${request.getContextPath()}/js/public-head.js"></script>
</head>
<body>

<div class="layui-row">
    <div class="layui-col-md12">
        <div class="layui-card">
            <div class="layui-card-body">
                <table class="layui-hide" id="test-table-reload" lay-filter="test-table-reload"></table>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">
    var layindex,layevent;
    layui.config({
        base: basePath+'/layui/lay/modules/'
    }).extend({
        formSelects: 'formSelects-v4'
    }).use([ 'table','form' ], function(){
        var table = layui.table;
        var $ = layui.$;
        var form = layui.form;

        var tableOption = {
            elem: '#test-table-reload'
            ,id: 'test-table-reload'
            ,height: 'full-200'
            ,page: false //开启分页
            ,data :[12.12]
            ,url:null
            ,limit:0
            ,toolbar:$("#dataSource-toolBar").html()
            ,cols: [[ //表头
                {title: '选择', width:80, type:"radio", fixed: 'left'}
                ,{field: 'typeNo', title: '状态编码' }
                ,{field: 'typeName', title: '状态描述'  }
                ,{field: 'typeColor', title: '颜色(RGB)',templet: function (d) {
                    var value = d.typeColor == null ?"":d.typeColor
                    return "<div style='background:rgb("+ d.typeColor+")'>"+  value +"</div>"
                } }
            ]]
        };

        function loadData(){
            tableOption.data = [];
            $.getJSON(basePath + '/appBordType',function(rst){
                tableOption.data = rst
                tableOption.limit = rst.length
                table.render(tableOption)
            })

        }

        var alarmId = ""
        table.on('toolbar(test-table-reload)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'add':
                    layer.open({
                        type: 2,
                        area: ['30%' , '60%'  ],
                        fix: false, //不固定
                        maxmin: true,
                        shadeClose: true,
                        shade:0.4,
                        offset: '0.5%',
                        scrollbar:true,
                        title:  "状态分类",
                        content: "${request.getContextPath()}/appBordType/show",
                        end: function(){
                            loadData()
                            return false;
                        }
                    });
                    break;
                case 'del':
                    if(checkStatus.data.length == 0){
                        layer.msg('请选择要操作记录',{icon:2});
                        return ;
                    }
                    $.getJSON(basePath + '/appBordType/delete',{id:alarmId},function(rst){
                        if(rst.statusCode == 200){
                            layer.msg('操作成功');
                            loadData()
                        }else{
                            layer.alert(rst.message,{icon:2})
                        }
                    })
                    break;
                case 'edit':

                    if(checkStatus.data.length == 0){
                        layer.msg('请选择要操作记录',{icon:2});
                        return ;
                    }

                    layer.open({
                        type: 2,
                        area: ['30%' , '60%'  ],
                        fix: false, //不固定
                        maxmin: true,
                        shadeClose: true,
                        shade:0.4,
                        offset: '0.5%',
                        scrollbar:true,
                        title:  "状态分类",
                        content: "${request.getContextPath()}/appBordType/show?id="+alarmId,
                        end: function(){
                            loadData()
                            return false;
                        }
                    });
                    break;
            };
        });

        table.on('radio(test-table-reload)', function(obj){
            alarmId = obj.data.id
        });
        loadData()
    });



</script>

<script type="text/html" id="dataSource-toolBar">
<div class="layui-btn-container">
    <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
    <button class="layui-btn layui-btn-sm" lay-event="edit">编辑</button>
    <button class="layui-btn layui-btn-sm" lay-event="del">删除</button>
</div>
</script>

</body>
</html>
